package com.lcq.study.leetcode.cjsf;

/**
 * @ClassName 初级算法第1章07题
 * @Description
 * @Author lichuanqi
 * @Date 2022/10/27 17:45
 * @Version 1.0
 **/
public class cjsf107 {
    public static void main(String[] args) {
        cjsf107 solution = new cjsf107();
        int[] ints = solution.plusOne(new int[]{9, 9, 9});
        for (int anInt : ints) {
            System.out.println(anInt);
        }
    }

    public int[] plusOne(int[] digits) {
        int sl = digits.length;
        int jw = 1;
        for (int i = sl-1; i>=0; i--){
            int num = digits[i]+jw;
            digits[i] = num%10;
            jw = num/10;
        }

        if (jw == 0){
            return digits;
        }

        int[] result = new int[sl + 1];
        result[0] = 1;
        return result;

    }
}
